<?php
include_once(dirname(__FILE__).'/../autoload.php');


class Selenium_TicketEditorTest extends Lib_SeleniumTestcase
{
    protected function openNewTicketWizard()
    {
        $this->clickButtonThatContainsText('Create ticket');
        $this->verifyTextPresent('New ticket');
        return $this;
    }

    public function test_openNewTicketWizard()
    {
        $this->login()->openNewTicketWizard();
        $this->verifyTextsPresent(array(
            'Pick a color', 'Save and', 'Close', 'Make sub-ticket', 'Make sibling',
            'Cancel'
        ));
    }

    public function test_createNewTicket_justName()
    {
        $this->login()->openNewTicketWizard();
        $this->fillForm('css=div#newTicketEditorWindow', array(
            'name' => 'Selenium test ticket'
        ));
        $this->clickButtonThatContainsText('Close');
        $this->verifyTextPresent('Ticket Selenium test ticket added');

        $expected = array(
            array('name' => 'Selenium test ticket',
                'reporterId' => 1));
        $actual = Lib_QueryWrapper::runQuery('SELECT name, reporterId FROM Ticket ORDER BY id DESC LIMIT 1');
        $this->assertEquals($expected, $actual);
    }

    public function test_createNewTicket_Moreinput()
    {
        $this->login()->openNewTicketWizard();
        $this->fillForm('css=div#newTicketEditorWindow', array(
            'name' => 'Selenium test ticket no 2',
            'originalEstimate' => '3 d',
            'description' => "Test proves that ticket info is correctly stored to database via user interface"
        ));
        $this->clickButtonThatContainsText('Close');
        $this->verifyTextPresent('Ticket Selenium test ticket no 2 added');

        $expected = array(
            array(
                'originalEstimate' => 18,
                'description' => "Test proves that ticket info is correctly stored to database via user interface"
            )
        );
        $actual = Lib_QueryWrapper::runQuery('SELECT originalEstimate, description FROM Ticket ORDER BY id DESC LIMIT 1');
        $this->assertEquals($expected, $actual);
    }

    //color-FFFF00
}